package cn.imvc.app.controllers.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Resource;
import cn.imvc.app.models.ResourceModel;
import cn.imvc.app.models.RoleResourceModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class RoleResourceControllerImpl implements RoleResourceController {
	public String roles;
	public int id;
	public String resources;
	public int[] resourceid;
	
	public void setId(int id) {
		this.id = id;
	}
	
	@Autowired
	private RoleResourceModel roleResourceModel;
	@Autowired
	private ResourceModel resourceModel;
	public String index() {
		roles=roleResourceModel.getRoles();
		return "role-resource/index";

	}
	public String show() {
		resources=roleResourceModel.getResources(id);
		return "role-resource/show";

	}
	public String create() {
		Set<Resource> resources=new HashSet<Resource>();
		if(resourceid!=null)
		for (int rid : resourceid) {
			resources.add(resourceModel.get(rid));
		}
		roleResourceModel.saveRoleResource(id, resources);
		return Render.json(new DialogBean("200", "保存成功","role-resource","closeCurrent"));

	}
}
